package com.chenqi.myblog.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.chenqi.myblog.mapper.TagMapper;
import com.chenqi.myblog.model.Tag;
import com.chenqi.myblog.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @description:
 * @program: myblog
 * @author: ChenQi
 * @create: 2021-02-2021/2/2-11-53
 */
@Service
@Transactional(rollbackFor = RuntimeException.class)
public class TagServiceImpl implements TagService {

    @Autowired
    private TagMapper tagMapper;

    @Override
    @Transactional(propagation = Propagation.SUPPORTS,readOnly = true)
    public List<Tag> findAllTag() {
        return tagMapper.selectList(null);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = RuntimeException.class)
    public void saveTag(Tag tag) {
        tagMapper.insert(tag);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = RuntimeException.class)
    public void removeTag(Integer id) {
        tagMapper.deleteById(id);
        tagMapper.deleteTagBlog(id);
    }

    @Override
    @Transactional(propagation = Propagation.SUPPORTS,readOnly = true)
    public List<Integer> findTagIdByBlogId(Integer id) {
        return tagMapper.findTagIdByBlogId(id);
    }

    @Override
    @Transactional(propagation = Propagation.SUPPORTS,readOnly = true)
    public Tag findTagById(Integer id) {
        return tagMapper.selectById(id);
    }

    @Override
    @Transactional(propagation = Propagation.SUPPORTS,readOnly = true)
    public Integer findTagCounts(Integer id) {
        return tagMapper.findTagCounts(id);
    }

    @Override
    @Transactional(propagation = Propagation.SUPPORTS,readOnly = true)
    public List<Integer> findBlogIdsByTagId(Integer tid) {
        return tagMapper.findBlogIdsByTagId(tid);
    }
}
